/**
 * @file main.cc
 * @author HaoyuWang (136046355@qq.com)
 * @brief 测试入口
 * @version 0.1
 * @date 2025-01-24
 * 
 * @copyright Copyright (c) 2025
 * 
 */

#include "sunnet.h"
#include "worker.h"
#include "common.h"
#include "log.h"

#include <unistd.h>

#include <memory>
#include <thread>
#include <string>
#include <cstdint>
#include <iostream>

using namespace std;

void Test(){
    auto pingType = make_shared<string>("ping");
    uint32_t ping1 = Sunnet::GetInstance().NewService(pingType);
    uint32_t ping2 = Sunnet::GetInstance().NewService(pingType);
    uint32_t pong = Sunnet::GetInstance().NewService(pingType);

    auto msg = Sunnet::GetInstance().MakeMsg(ping1, new char[common::BUFF_LEN]{'h', 'e', 'l', 'l', 'o', '\0'}, common::BUFF_LEN);
    auto msg2 = Sunnet::GetInstance().MakeMsg(ping2, new char[common::BUFF_LEN]{'h', 'i', '\0'}, common::BUFF_LEN);

    Sunnet::GetInstance().Send(pong, msg);
    Sunnet::GetInstance().Send(pong, msg2);
}

void TestSocket(){
    int fd = Sunnet::GetInstance().Listen(8001, 1);
    sleep(15);
    Sunnet::GetInstance().CloseConn(fd);
}

void TestLua(){
    auto t = make_shared<string>("main");
    uint32_t main = Sunnet::GetInstance().NewService(t);
}

void TestSpdlog(){
    LOG_DEBUG("hello!!{} hhh {}", 111, 222);
}

int main(int argc, char const *argv[])
{
    // daemon(0, 0);
    Log::GetInstance().Init();
    Sunnet::GetInstance().Start();

    TestLua();

    Sunnet::GetInstance().Wait();
    
    return 0;
}
